﻿namespace Central.Linq {

	/// <summary>
	/// Расширение AggregateFunction
	/// </summary>
	public static class AggregateFunctionExtensions {

		/// <summary>
		/// Метод формирования предиката агрегирующей функции
		/// </summary>
		/// <param name="function"></param>
		/// <returns></returns>
		public static string GeneratePredicate(this AggregateFunction function) {
			{
				string result = string.Empty;
				switch (function) {
					case AggregateFunction.Average:
						result = "SUM({0})/COUNT({0}<>null)";
						break;
					default:
						result = function.ToString() + "({0})";
						break;
				}
				return result;
			}
		}
	}
}